<?php

use App\Http\Controllers\AdminMemberLevelController;
use App\Http\Controllers\AdminMenuController;
use App\Http\Controllers\AdminResourceCategoryController;
use App\Http\Controllers\AdminResourceController;
use App\Http\Controllers\AdminRoleController;
use App\Http\Controllers\AdminUserController;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

// 不需要登录的接口
Route::group(['middleware' => ['api']],function(Router $router){
    // 不需要登录
    $router->group(['prefix' => 'user'],function ($router) {
        // 注册
        $router->post('register',[AdminUserController::class,'register']);
        // 登录
        $router->post('login',[AdminUserController::class,'login']);
    });
});

// 需要登录的接口
Route::group(['middleware' => ['auth:admin','api']],function(Router $router){
    // 需要登录
    $router->group(['prefix' => 'user'],function ($router) {
        // 刷新token
        $router->post('refresh',[AdminUserController::class,'refresh']);
        // 获取当前登录用户信息
        $router->get('/info',[AdminUserController::class,'info']);
        // 登出功能
        $router->post('logout',[AdminUserController::class,'logout']);
        // 根据用户名或姓名分页获取用户列表
        $router->get('list',[AdminUserController::class,'list']);
        // 获取指定用户信息
        $router->get('/{id}',[AdminUserController::class,'getById'])->where('id', '[0-9]+');
        // 修改指定用户信息
        $router->post('/update/{id}',[AdminUserController::class,'updateById'])->where('id', '[0-9]+');
        // 修改指定用户密码-非登录用户
        $router->post('/updatePassword',[AdminUserController::class,'updatePassword']);
        // 重置密码
        $router->post('/reset',[AdminUserController::class,'reset']);
        // 删除指定用户信息
        $router->post('/delete/{id}',[AdminUserController::class,'delete'])->where('id', '[0-9]+');
        // 修改帐号状态
        $router->post('/updateStatus/{id}',[AdminUserController::class,'updateStatus'])->where('id', '[0-9]+');
        // 给用户分配角色
        $router->post('/role/update',[AdminUserController::class,'updateRole']);
        // 获取指定用户的角色
        $router->get('/role/{adminId}',[AdminUserController::class,'getRoleList']);
    });
    $router->group(['prefix' => 'role'],function ($router) {
        // 创建角色
        $router->post('/create',[AdminRoleController::class,'create']);
        // 修改角色
        $router->post('/update/{id}',[AdminRoleController::class,'update']);
        // 删除角色
        $router->post('/delete/{id}',[AdminRoleController::class,'delete']);
        // 批量删除角色
        $router->post('/delete_batch',[AdminRoleController::class,'deleteBatch']);
        // 获取所有角色
        $router->get('/list_all',[AdminRoleController::class,'listAll']);
        // 根据角色名称分页获取角色列表
        $router->get('/list',[AdminRoleController::class,'list']);
        // 修改角色状态
        $router->post('/updateStatus/{id}',[AdminRoleController::class,'updateStatus']);
        // 获取角色相关菜单
        $router->get('/listMenu/{roleId}',[AdminRoleController::class,'listMenu']);
        // 获取角色相关资源
        $router->get('/listResource/{roleId}',[AdminRoleController::class,'listResource']);
        // 给角色分配菜单
        $router->post('/allocMenu',[AdminRoleController::class,'allocMenu']);
        // 给角色分配资源
        $router->post('/allocResource',[AdminRoleController::class,'allocResource']);
    });
    $router->group(['prefix' => 'menu'],function ($router) {
        // 创建后台菜单
        $router->post('/create',[AdminMenuController::class,'create']);
        // 修改后台菜单
        $router->post('/update/{id}',[AdminMenuController::class,'update']);
        // 查看菜单详情
        $router->get('/get/{id}',[AdminMenuController::class,'getById']);
        // 删除菜单
        $router->post('/delete/{id}',[AdminMenuController::class,'delete']);
        // 分页获取菜单信息
        $router->get('/list/{parentId}',[AdminMenuController::class,'list']);
        // 树形结构返回所有菜单列表
        $router->get('/treeList',[AdminMenuController::class,'treeList']);
        // 修改菜单显示状态
        $router->post('/updateHidden/{id}',[AdminMenuController::class,'updateHidden']);
    });
    $router->group(['prefix' => 'member/level'],function ($router) {
        // 会员等级信息
        $router->get('/list',[AdminMemberLevelController::class,'list']);
    });
    $router->group(['prefix' => 'resource/category'],function ($router) {
        // 查询所有后台资源分类
        $router->get('/listAll',[AdminResourceCategoryController::class,'listAll']);
        // 添加后台资源分类
        $router->post('/create',[AdminResourceCategoryController::class,'create']);
        // 修改后台资源分类
        $router->post('/update/{id}',[AdminResourceCategoryController::class,'update']);
        // 根据ID删除后台资源分类
        $router->post('/delete/{id}',[AdminResourceCategoryController::class,'delete']);
    });

    $router->group(['prefix' => 'resource'],function ($router) {
        // 添加后台资源
        $router->post('/create',[AdminResourceController::class,'create']);
        // 修改后台资源
        $router->post('/update/{id}',[AdminResourceController::class,'update']);
        // 根据ID获取资源详情
        $router->get('/get/{id}',[AdminResourceController::class,'getById']);
        // 根据ID删除后台资源
        $router->post('/delete/{id}',[AdminResourceController::class,'delete']);
        // 分页模糊查询后台资源
        $router->get('/list',[AdminResourceController::class,'list']);
        // 查询所有后台资源
        $router->get('/listAll',[AdminResourceController::class,'listAll']);
    });

});
